const hospital = require('../service/hospital');

// 获取医院及模糊搜索
const getsoco = async (ctx) => {
    let res = await hospital.Getsoco(ctx.query);
    if (res.length > 0) {
        return ctx.body = {
            code: 200,
            message: '获取成功',
            data: res
        }
    } else {
        return ctx.body = {
            code: 400,
            message: '暂无数据,请稍后再试或联系管理员刘浩QQ499735432,电话15545508600'
        }
    }
}

// 获取医院的等级
const getsocolv = async (ctx) => {
    let res = await hospital.Getsocolv(ctx.query);
    if (res.length > 0) {
        return ctx.body = {
            code: 200,
            message: '获取成功',
            data: res
        }
    } else {
        return ctx.body = {
            code: 400,
            message: '暂无数据,请稍后再试或联系管理员刘浩QQ499735432,电话15545508600'
        }
    }
}

// 添加医院
const addsocolist = async (ctx) => {
    let res = await hospital.Addsocolist(ctx.request.body);
    if (res.affectedRows > 0) {
        return ctx.body = {
            code: 200,
            message: '添加成功',
        }
    } else {
        return ctx.body = {
            code: 400,
            message: '添加失败,请稍后再试或联系管理员刘浩QQ499735432,电话15545508600'
        }
    }
}

// 删除医院
const delsocolist = async (ctx) => {
    let res = await hospital.Delsocolist(ctx.query);
    if (res.affectedRows > 0) {
        return ctx.body = {
            code: 200,
            message: '删除成功',
        }
    } else {
        return ctx.body = {
            code: 400,
            message: '删除失败,请稍后再试或联系管理员刘浩QQ499735432,电话15545508600'
        }
    }
}

// 修改医院的数据
const updatesocolist = async (ctx) => {
    let res = await hospital.Updatesocolist(ctx.request.body);
    if (res.affectedRows > 0) {
        return ctx.body = {
            code: 200,
            message: '修改成功',
        }
    } else {
        return ctx.body = {
            code: 400,
            message: '修改失败,请稍后再试或联系管理员刘浩QQ499735432,电话15545508600'
        }
    }
}

module.exports = {
    getsoco,//获取医院及模糊搜索 
    getsocolv,//获取医院的等级
    addsocolist,//添加医院
    delsocolist,//删除医院
    updatesocolist,//修改医院的数据
}